﻿using CPPEI;
using CPPEI.WebApi;
using SLG.Domain;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

using Ser = SLG.Domain.Services;
using Ent = SLG.Domain.Entities;
using V = SLG.Domain.Views;

namespace SLG.WebApi.Data
{
    /// <summary>
    /// 基础数据-获取可以选择的国王头像
    /// </summary>
    [AuthGetAction("BD", "GetKings", "1.0")]
    public class GetKingsAction : BaseAction<GetKingsParams, GetKingsResult>
    {
        protected override ActionResult<GetKingsResult> OnExecute(ActionContext context, SysParameters sysParams, GetKingsParams opParams)
        {
            Ser.BDService service = new Ser.BDService();
            ListResult<V.V_BD_King> serResult = service.GetKings(opParams.Race);

            if (serResult.IsSuccess)
            {
                GetKingsResult actResult = new GetKingsResult();

                for (int index = 0; index < serResult.Data.Count; index++)
                {
                    GetKingsResult.Item item = new GetKingsResult.Item();

                    item.Id = serResult.Data[index].Id;
                    item.Avatar = serResult.Data[index].Avatar;

                    actResult.Items.Add(item);
                }
                return new ActionResult<GetKingsResult>(actResult);
            }
            else
            {
                return new ActionResult<GetKingsResult>(serResult);
            }
        }
    }

    public class GetKingsParams
    {
        public int Race { get; set; }
    }

    public class GetKingsResult
    {
        public List<Item> Items = new List<Item>();

        public class Item
        {
            public int Id { get; set; }

            public string Avatar { get; set; }
        }
    }
}
